package study.proxy.jkdproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JdkMethodProxy implements InvocationHandler {

    private Object method;

    public Object newInstance(Object method){

        this.method = method;

        Class<?> aClass = method.getClass();

        return Proxy.newProxyInstance(aClass.getClassLoader(),aClass.getInterfaces(),this);


    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        begin();

        Object  invoke = method.invoke(this.method, args);


        after();



        return invoke;
    }

    private void after() {
        System.out.println("动态代理执行后。。。。。。");

    }

    private void begin() {
        System.out.println("动态代理执行前。。。。。。");
    }

}
